import sys
import typing
from pathlib import Path
from typing import Dict, List, Optional, Tuple, Union

from PySide6.QtCore import QModelIndex, QPointF, Qt, Signal, Slot
from PySide6.QtGui import QColor, QFont, QPalette, QStandardItem, QStandardItemModel
from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QMessageBox, QTableView, QStyle

from ui.main_window_ui import Ui_MainWindow


PROGRAM_NAME = "SKD MODBUS CMD"
ORG_NAME = "SKD"

ABOUT_TEXT = f'''
{PROGRAM_NAME}

A python program using PySide6 GUI framework.
'''


class MainWindow(QMainWindow):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # 图标和标题
        self.setWindowIcon(QApplication.style().standardIcon(QStyle.StandardPixmap.SP_TitleBarMenuButton))
        self.setWindowTitle(PROGRAM_NAME)        

        # menu action
        self.ui.action_about.triggered.connect(self.show_about_dialog)
        self.ui.action_about_qt.triggered.connect(QApplication.aboutQt)
        self.ui.action_about_qt.setIcon(QApplication.style().standardIcon(QStyle.StandardPixmap.SP_TitleBarMenuButton))

    @Slot()  # type: ignore
    def show_about_dialog(self):
        QMessageBox.about(self, 'About', ABOUT_TEXT)
